import React from 'react'
import Child from './Child'
import { createContext } from 'react'
const { Provider } = createContext()

export default class Parent extends React.Component {
  state = {
    money: 10000,
  }

  // 回调函数
  buyPhone = price => {
    this.setState({
      money: this.state.money - price,
    })
  }

  render() {
    const { money } = this.state
    return (
      <Provider value="red">
        <div>
          <h1>我是父组件：{money}</h1>
          {/* 将数据传递给子组件 */}
          <Child money={money} buyPhone={this.buyPhone} />
        </div>
      </Provider>
    )
  }
}
